using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Portal.Core.DAL;
using System.ComponentModel;

namespace Portal.BO.Editoral.Question
{
    public class QuestionHelper
    {
        public QuestionHelper()
        {
        }
        [DataObjectMethod(DataObjectMethodType.Select)]
        public static DataTable Question_GetListByCatID(int PageSize, int StartRow, string Cat_ID, string noidung)
        {
            int EndRow = StartRow + PageSize;

            if (noidung == null)
                noidung = "";
            
            using (MainDB objdb = new MainDB())
            {
                return objdb.StoredProcedures.Question_GetListByCatID(StartRow, EndRow, Cat_ID, noidung);
            }
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public static Int32 Question_CountGetListByCatID(string Cat_ID, string noidung)
        {
            if (noidung == null)
                noidung = "";

            using (MainDB objdb = new MainDB())
            {
                return Convert.ToInt32(objdb.StoredProcedures.Question_CountGetListByCatID(Cat_ID, noidung).Rows[0][0]);
            }
        }

        public static void DeleteQuestion(string strHoiID)
        {
            using (MainDB objdb = new MainDB())
            {
                objdb.SelectQuery(" Delete Answer Where Hoi_ID IN (" + strHoiID + ")");
                objdb.SelectQuery(" Delete Question Where Hoi_ID IN (" + strHoiID + ")");
            }
        }

        public static string GetQuestionByID(string Hoi_ID)
        {
            DataTable dt;
            using (MainDB objdb = new MainDB())
            {
                dt = objdb.SelectQuery(" Select Noi_Dung From Question Where Hoi_ID = " + Hoi_ID);
            }
            if (dt.Rows.Count > 0)
                return dt.Rows[0][0].ToString();
            else
                return "";
        }

        public static void Update(string strHoi_ID, string content)
        {
            using (MainDB objdb = new MainDB())
            {
                objdb.SelectQuery(" Update Question Set Noi_Dung = N'" + content + "' Where Hoi_ID = " + strHoi_ID);
            }
        }
    }
}
